package com.itheima.dubbo.web;

import com.itheima.dubbo.User;
import com.itheima.dubbo.UserInterface;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @作者 Azer
 * @创建日期 2021/12/10 19:51
 **/
@RestController
@RequestMapping("user")
public class UserController {

    //如果相同的配置在提供方和消费方同时配置 则消费方优于提供方
//    @DubboReference(timeout = 5000) //远程调用
//    @DubboReference(retries = 0)
    @DubboReference( check = false,timeout = 5000)
    private UserInterface userInterface;

    @GetMapping("hello")
    public String hello(String username){
        //隐式传参
        RpcContext.getContext().setAttachment("jwt","九头蛇万岁");
      return   userInterface.hello(username);

    }

    @GetMapping("findUser")
    public User findUser(String name){
        User userVO=new User();
        userVO.setName(name);
     return   userInterface.findUser(userVO);
    }

}
